import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;

/**
 * @author 帅小伙
 * @date 2022/1/1
 * @description   哨兵方式启动
 */
public class SentinelJedis {

    private static JedisSentinelPool jedisSentinelPool = null;

    private SentinelJedis(){};

    public static Jedis getJedisFromSentinelPool(){
        if(jedisSentinelPool == null){
            // 配置主服务器的  ip 端口号
            HashSet<String> sentinelSet = new HashSet();
            sentinelSet.add("47.96.19.90:23330");
            JedisPoolConfig config = new JedisPoolConfig();
            config.setMaxIdle(200);
            config.setMaxIdle(32);
            config.setMaxWaitMillis(10*1000);
            config.setBlockWhenExhausted(true);
            config.setTestOnBorrow(true);
            jedisSentinelPool = new JedisSentinelPool("mymaster",sentinelSet,config);
        }
        return jedisSentinelPool.getResource();
    }

}
